import React from "react";
import {observer, inject} from 'mobx-react';
import {toJS} from "mobx";
import {withRouter} from 'react-router-dom';
import {Tools, Toast, Icon} from "weaver-mobile";
import {ListAdvanced} from "weaver-mobile-page";

import './style/index.less'

const getLabel = Tools.getLabel;

@withRouter
@inject("updateOperatorStore")
@observer
export default class UpdateOperator extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
            <div className={"updateOperatorCotent"}>
                {this.getUpdateOerateList()}
            </div>
        );
    }

    getUpdateOerateList = () => {
        const {updateOperatorStore} = this.props;
        const {uoList = {}} = updateOperatorStore;
        return <ListAdvanced
            withSwipeAction
            swipeActionProps={this.getSwipeActionProps()}
            className={"UpdateOperatCom"}
            rowKey={"id"}
            showSearchBar={false}
            store={uoList}
            getTemplate={(template) => {
                return ({default: this.getTemplate()})
            }}
        />

    }

    getTemplate = () => {
        const template = [
            {
                key: 'col1',
                style: {flex: 'none'},
                render: (data) => {
                    return <Icon type="delete-o" onClick={() => {
                        this.goDeleteFlow(data)
                    }}/>;
                },
            },
            {
                key: 'col2',
                configs: [
                    {
                        key: 'row1',
                        render: (data, value, index) => {
                            const {
                                userdeptspan, userdept, userid, useridspan, nodeidspan, nodeid,
                                receivedatespan, receivedate, isremarkspan, isremark
                            } = data;
                            return <div className={"list_row1_item"}>
                                <div className={"list_item"}>
                                    <span className={"title"}>{getLabel(511479, "流转环节") + ":"}</span>
                                    <span className={"content"}>{nodeidspan || nodeid}</span>
                                </div>
                                <div className={"operator list_item"}>
                                    <span className={"title"}>{getLabel(99, "操作者") + ":"}</span>
                                    <span className={"content"}>{useridspan || userid}</span>
                                </div>
                                <div className={"list_item"}>
                                    <span className={"title"}>{getLabel(385898, "操作者部门") + ":"}</span>
                                    <span className={"content"}>{userdeptspan}</span>
                                </div>

                                <div className={"list_item"}>
                                    <span className={"title"}>{getLabel(17994, "接收日期") + ":"}</span>
                                    <span className={"content"}>{receivedatespan || receivedate}</span>
                                </div>
                                <div className={"list_item"}>
                                    <span className={"title"}>{getLabel(503040, "流转状态") + ":"}</span>
                                    <span className={"content"}>{isremarkspan || isremark}</span>
                                </div>
                            </div>
                        }
                    },
                ],
            },
        ];
        return template;
    }

    /**
     * 滑动按钮
     * @returns {{right: *[]}}
     */
    getSwipeActionProps = () => ({
        right: [
            {
                text: getLabel(91, "删除"),
                onPress: this.goDeleteFlow,
                className: 'swipeDelete'
            },
        ],
    });

    goDeleteFlow = (data = {}) => {
        const {updateOperatorStore} = this.props;
        if (data && data.id) {
            const {reducedSignature} = updateOperatorStore;
            let sltids = data.id + "_" + data.isremark;
            reducedSignature({sltids}, {showcontent: getLabel(520042, "确定要减签吗?")})
        } else {
            Toast.fail(getLabel(519461, "请选择需要删除的数据！"), 1)
        }
    }
}